package com.our.base.easylog.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

/**
 * 过滤器
 *
 * name:李瑞兵
 * @author admin
 * @date 2023/12/11
 */
@Slf4j
@WebFilter
public class ReqFilter implements Filter {
    public ReqFilter() {
        System.out.println("init reqFilter");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("咚巴拉,咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉咚巴拉");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        Map<String, String[]> parameterMap = req.getParameterMap();
        String requestURI = req.getRequestURI();
        log.info("过滤器url={}, params={}", requestURI, parameterMap);
        chain.doFilter(req, response);
    }

    @Override
    public void destroy() {
        log.info("毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧毁灭吧");
    }
}